// 用户模块
export default {
  namespaced: true,
  state () {
    return {
      userInfo: {},
      userToken: ''
    }
  },
  getters: {
    phone: state => state.userInfo.phone,
    idNumber: state => state.userInfo.user.idNumber,
    accountCreateTime: state => state.userInfo.createTime
  },
  mutations: {
    setUserInfo (state, data) {
      state.userInfo = data
    }
  },
  actions: {
    handleLogin ({ commit }, { phone, password }) {
      return new Promise((resolve, reject) => {
        login({
          phone,
          password,
          type: 'user',
          loginType: 'RT',
          domainName: config.baseOrigin
        }).then(({ data }) => {
          commit('setUserInfo', data || {})
          resolve()
        }).catch(err => {
          reject(err)
        })
      })
    },
    handleLogOut ({ commit }) {
      return new Promise((resolve, reject) => {
        logout({}).then(() => {
          commit('setUserInfo', {})
          resolve()
        }).catch((err) => {
          reject(err)
        })
      })
    }
  }
}
